home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_qt.idb / usr / freeware / include / Qt / qdict.h.z / qdict.h
Encoding:
C/C++ Source or Header  |  1998-10-28  |  6.1 KB  |  166 lines

  1. /****************************************************************************
  2. ** $Id: qdict.h,v 2.5 1998/07/03 00:09:43 hanord Exp $
  3. **
  4. ** Definition of QDict template/macro class
  5. **
  6. ** Created : 920821
  7. **
  8. ** Copyright (C) 1992-1998 Troll Tech AS.  All rights reserved.
  9. **
  10. ** This file is part of Qt Free Edition, version 1.40.
  11. **
  12. ** See the file LICENSE included in the distribution for the usage
  13. ** and distribution terms, or http://www.troll.no/free-license.html.
  14. **
  15. ** IMPORTANT NOTE: You may NOT copy this file or any part of it into
  16. ** your own programs or libraries.
  17. **
  18. ** Please see http://www.troll.no/pricing.html for information about 
  19. ** Qt Professional Edition, which is this same library but with a
  20. ** license which allows creation of commercial/proprietary software.
  21. **
  22. *****************************************************************************/
  23.  
  24. #ifndef QDICT_H
  25. #define QDICT_H
  26.  
  27. #ifndef QT_H
  28. #include "qgdict.h"
  29. #endif // QT_H
  30.  
  31.  
  32. #if defined(USE_MACROCLASS)
  33.  
  34. #include "qgeneric.h"
  35.  
  36. #if !defined(name2)
  37. #define name2(a,b)    name2_xx(a,b)
  38. #define name2_xx(a,b) a##b
  39. #endif
  40.  
  41. #if defined(DEFAULT_MACROCLASS)
  42. #define QDictdeclare QDictMdeclare
  43. #define QDict QDictM
  44. #endif
  45. #define QDictM(type) name2(QDictM_,type)
  46.  
  47. #define QDictMdeclare(type)                              \
  48. class QDictM(type) : public QGDict                          \
  49. {                                          \
  50. public:                                          \
  51.     QDictM(type)(int size=17,bool cs=TRUE,bool ck=TRUE):QGDict(size,cs,ck,0){}\
  52.     QDictM(type)( const QDictM(type) &d ) : QGDict(d) {}              \
  53.    ~QDictM(type)()            { clear(); }                  \
  54.     QDictM(type) &operator=(const QDictM(type) &d)                  \
  55.             { return (QDictM(type)&)QGDict::operator=(d); }          \
  56.     uint  count()   const        { return QGDict::count(); }          \
  57.     uint  size()    const        { return QGDict::size(); }          \
  58.     bool  isEmpty() const        { return QGDict::count() == 0; }      \
  59.     void  insert( const char *k, const type *d )                  \
  60.                     { QGDict::look(k,(GCI)d,1); }          \
  61.     void  replace( const char *k, const type *d )                  \
  62.                     { QGDict::look(k,(GCI)d,2); }          \
  63.     bool  remove( const char *k )    { return QGDict::remove(k); }          \
  64.     type *take( const char *k )        { return (type *)QGDict::take(k); }   \
  65.     void  clear()            { QGDict::clear(); }              \
  66.     void  resize( uint n )        { QGDict::resize(n); }              \
  67.     type *find( const char *k ) const                          \
  68.             { return (type *)((QGDict*)this)->QGDict::look(k,0,0);}   \
  69.     type *operator[]( const char *k ) const                      \
  70.             { return (type *)((QGDict*)this)->QGDict::look(k,0,0);}   \
  71.     void  statistics() const        { QGDict::statistics(); }          \
  72. private:                                      \
  73.     void  deleteItem( GCI d )    { if ( del_item ) delete (type *)d; }          \
  74. }
  75.  
  76.  
  77. #if defined(DEFAULT_MACROCLASS)
  78. #define QDictIteratordeclare QDictIteratorMdeclare
  79. #define QDictIterator QDictIteratorM
  80. #endif
  81. #define QDictIteratorM(type) name2(QDictIteratorM_,type)
  82.  
  83. #define QDictIteratorMdeclare(type)                          \
  84. class QDictIteratorM(type) : public QGDictIterator                  \
  85. {                                          \
  86. public:                                          \
  87.     QDictIteratorM(type)(const QDictM(type) &d) :QGDictIterator((QGDict &)d){}\
  88.    ~QDictIteratorM(type)()    {}                          \
  89.     uint  count()   const     { return dict->count(); }                  \
  90.     bool  isEmpty() const     { return dict->count() == 0; }              \
  91.     type *toFirst()          { return (type *)QGDictIterator::toFirst(); }   \
  92.     operator type *() const   { return (type *)QGDictIterator::get(); }          \
  93.     type *current()   const   { return (type *)QGDictIterator::get(); }          \
  94.     const char *currentKey() const                          \
  95.                   { return QGDictIterator::getKey(); }          \
  96.     type *operator()()          { return (type *)QGDictIterator::operator()(); }\
  97.     type *operator++()          { return (type *)QGDictIterator::operator++(); }\
  98.     type *operator+=(uint j)  { return (type *)QGDictIterator::operator+=(j);}\
  99. }
  100.  
  101. #endif // USE_MACROCLASS
  102.  
  103.  
  104. #if defined(USE_TEMPLATECLASS)
  105.  
  106. #if defined(DEFAULT_TEMPLATECLASS)
  107. #undef    QDict
  108. #define QDict QDictT
  109. #endif
  110.  
  111. template<class type> class QDictT : public QGDict
  112. {
  113. public:
  114.     QDictT(int size=17,bool cs=TRUE,bool ck=TRUE) : QGDict(size,cs,ck,0) {}
  115.     QDictT( const QDictT<type> &d ) : QGDict(d) {}
  116.    ~QDictT()                { clear(); }
  117.     QDictT<type> &operator=(const QDictT<type> &d)
  118.             { return (QDictT<type>&)QGDict::operator=(d); }
  119.     uint  count()   const        { return QGDict::count(); }
  120.     uint  size()    const        { return QGDict::size(); }
  121.     bool  isEmpty() const        { return QGDict::count() == 0; }
  122.     void  insert( const char *k, const type *d )
  123.                     { QGDict::look(k,(GCI)d,1); }
  124.     void  replace( const char *k, const type *d )
  125.                     { QGDict::look(k,(GCI)d,2); }
  126.     bool  remove( const char *k )    { return QGDict::remove(k); }
  127.     type *take( const char *k )        { return (type *)QGDict::take(k); }
  128.     void  clear()            { QGDict::clear(); }
  129.     void  resize( uint n )        { QGDict::resize(n); }
  130.     type *find( const char *k ) const
  131.             { return (type *)((QGDict*)this)->QGDict::look(k,0,0); }
  132.     type *operator[]( const char *k ) const
  133.             { return (type *)((QGDict*)this)->QGDict::look(k,0,0); }
  134.     void  statistics() const        { QGDict::statistics(); }
  135. private:
  136.     void  deleteItem( GCI d )    { if ( del_item ) delete (type *)d; }
  137. };
  138.  
  139.  
  140. #if defined(DEFAULT_TEMPLATECLASS)
  141. #undef    QDictIterator
  142. #define QDictIterator QDictIteratorT
  143. #endif
  144.  
  145. template<class type> class QDictIteratorT : public QGDictIterator
  146. {
  147. public:
  148.     QDictIteratorT(const QDictT<type> &d) :QGDictIterator((QGDict &)d) {}
  149.    ~QDictIteratorT()          {}
  150.     uint  count()   const     { return dict->count(); }
  151.     bool  isEmpty() const     { return dict->count() == 0; }
  152.     type *toFirst()          { return (type *)QGDictIterator::toFirst(); }
  153.     operator type *() const   { return (type *)QGDictIterator::get(); }
  154.     type *current()   const   { return (type *)QGDictIterator::get(); }
  155.     const char *currentKey() const
  156.                   { return QGDictIterator::getKey(); }
  157.     type *operator()()          { return (type *)QGDictIterator::operator()(); }
  158.     type *operator++()          { return (type *)QGDictIterator::operator++(); }
  159.     type *operator+=(uint j)  { return (type *)QGDictIterator::operator+=(j);}
  160. };
  161.  
  162. #endif // USE_TEMPLATECLASS
  163.  
  164.  
  165. #endif // QDICT_H
  166.